package com.example.jucdemo.waitnotify.dmeo2;

/**
 * @Author by KoVaVo
 * @Date 2023-05-20 19:15
 * @Desc: 生产者
 */
public class code02_Producer {

    private String lock;

    public code02_Producer(String lock){
        super();
        this.lock = lock;
    }

    public void setValue(){
        try {
            synchronized (lock){
                if(!"".equals(code01_ValueObject.value)){
                    //如果不是空的，则说明就需要消费了
                    lock.wait();
                }
                String value = System.currentTimeMillis() + " " + System.nanoTime();
                System.out.println("set 的value值：" + value);
                code01_ValueObject.value = value;
                lock.notify();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }


}
